package org.example.springbookdemo.dao;

import org.example.springbookdemo.model.BookInfo;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author: Themberfue
 * @date: 2025/1/23 11:13
 * @description:
 */
// ? 将该对象交给spring管理 (IoC，Inversion of Control)
@Repository
public class BookDao {
    /**
     * mock从数据库中查询数据
     */
    public List<BookInfo> mockData(){
        List<BookInfo> bookList = new ArrayList<>();
        for (int i = 1; i <= 15; i++) {
            BookInfo bookInfo = new BookInfo();
            bookInfo.setBookId(i);
            bookInfo.setBookName("图书"+ i);
            bookInfo.setAuthor("作者"+ i);
            bookInfo.setPublish("出版社"+ i);
            bookInfo.setNum(new Random().nextInt(100));
            bookInfo.setPrice(new BigDecimal(new Random().nextInt(100)));
            bookInfo.setStatus(i % 5 == 0 ? 2 : 1); // 1-可借阅   2-不可借阅
            bookList.add(bookInfo);
        }
        return bookList;
    }
}
